define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

	var Controller = {
		index  : function () {
			// 初始化表格参数配置
			Table.api.init({
				extend : {
					index_url  : 'qingdongwms/finance/account/index',
					add_url: 'qingdongwms/finance/account/add',
					edit_url: 'qingdongwms/finance/account/edit',
					del_url: 'qingdongwms/finance/account/del',
					table      : 'account',
				}
			});

			var table = $("#table");

			// 初始化表格
			table.bootstrapTable({
				url          : $.fn.bootstrapTable.defaults.extend.index_url,
				pk           : 'id',
				sortName     : 'id',
				fixedColumns : true,
				fixedNumber  : 2,
				search:false,
				searchFormVisible:true,
				columns      : [
					[
						{checkbox : true},
						{field : 'deposit', title : '开户行', fixedColumns : true,operate:'like'},
						{field : 'name', title : '收款账号名称',operate:'like'},
						{field : 'account', title : '收款账号',operate:false},
						{field : 'status', title : '状态', formatter : Table.api.formatter.status,
							searchList : {0 : '禁用', 1 : '正常'}},
						{field : 'type', title : '账户类型', formatter : Table.api.formatter.status,
							searchList : {'public' : '公账', 'private' : '私账'}},
						{field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: false, addclass: 'datetimerange', sortable: true},
						{
							field     : 'operate',
							title     : __('Operate'),
							table     : table,
							events    : Table.api.events.operate,
							formatter : Table.api.formatter.operate,
							buttons   : [
								{
									name: 'edit',
									text: __('编辑'),
									title: __('编辑'),
									classname: 'records btn-dialog',
									url: 'qingdongwms/finance/account/edit',
									visible: function (row) {
										//返回true时按钮显示,返回false隐藏
										return true;
									}
								},
								{
									name: 'del',
									text: __('删除'),
									title: __('删除'),
									classname: 'records btn-ajax',
									url: 'qingdongwms/finance/account/del',
									confirm: '确定要删除吗?',
									refresh:true,
									error: function (data, ret) {
										console.log(data, ret);
										Layer.alert(ret.msg);
										return false;
									},
									visible: function (row) {
										//返回true时按钮显示,返回false隐藏
										return true;
									}
								},
							]
						}
					]
				]
			});
			$('.y_submit').on('click',function(){
				$("form[role=form]").submit();
			})
			// 为表格绑定事件
			Table.api.bindevent(table);
		},
		add    : function () {
			Controller.api.bindevent();
		},
		edit    : function () {
			Controller.api.bindevent();
		},
		api    : {
			bindevent : function () {
				Form.api.bindevent($("form[role=form]"), function(data, ret){
					//这里是表单提交处理成功后的回调函数，接收来自php的返回数据
					Fast.api.close(data);//这里是重点
				});
			}
		}
	};
	return Controller;
});